/**
 * Definition for a binary tree node.
 * public class TreeNode {
 * int val;
 * TreeNode left;
 * TreeNode right;
 * TreeNode() {}
 * TreeNode(int val) { this.val = val; }
 * TreeNode(int val, TreeNode left, TreeNode right) {
 * this.val = val;
 * this.left = left;
 * this.right = right;
 * }
 * }
 */
class Solution {
    public int maxDepth(TreeNode root) {
        //根节点 高度是0
        if (root == null){
            return 0;
        }
        //叶结点 高度是1
        if (root != null && root.left == null && root.right == null){
            return 1;
        }
        return max(maxDepth(root.left),maxDepth(root.right))+1;
    }

    private int max(int x, int y) {
        return x > y ? x : y;
    }
}
//leetcode submit region end(Prohibit modification and deletion)
